/**
 * @program: clms-second
 * @description: 菜单控制层
 * @author: mitu_echo
 * @create: 2021-07-22 16:35
 **/

package com.second.system.controller;

import com.second.common.pojo.R;
import com.second.system.pojo.entity.Menu;
import com.second.system.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    public MenuService menuService;

    @ApiOperation("查询用户拥有的菜单")
    @RequestMapping("/showUserHasMenu")
    public R showUserHasMenu() {
        return menuService.showUserHasMenu();
    }

    @ApiOperation("查询全部的菜单，父子关系查询")
    @RequestMapping("/showAllMenu")
    public R showAllMenu() {
       return menuService.showAllMenu();
    }

    @ApiOperation("查询角色拥有的菜单的菜单id")
    @RequestMapping("/showRoleHasMenuId")
    public R showRoleHasMenuId(Integer roleid) {
        return menuService.showRoleHasMenuId(roleid);
    }

    @ApiOperation("修改角色拥有的菜单")
    @RequestMapping("/updateRoleHasMenu")
    public R updateRoleHasMenu(@RequestParam("menuidList") List<Integer> menuidList, Integer roleid) {

        return menuService.updateRoleHasMenu(menuidList,roleid);
    }

    @ApiOperation("查询全部的父菜单")
    @RequestMapping("/showAllFatherMenu")
    public R showAllFatherMenu() {

        return menuService.showAllFatherMenu();
    }

    @ApiOperation("添加菜单")
    @RequestMapping("/addMenu")
    public R addMenu(@RequestBody Menu menu) {

        System.out.println(menu);
        return menuService.addMenu(menu);
    }

    @ApiOperation("查询全部的菜单，无父子关系")
    @RequestMapping("/showMenu")
    public R showMenu() {

        return menuService.showMenu();
    }

    @ApiOperation("删除菜单")
    @RequestMapping("/deleteMenuByMenuid")
    public R deleteMenuByMenuid(Integer mid) {

        return menuService.deleteMenuByMenuid(mid);
    }

}
